<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>注 册</title>
	<link rel="stylesheet" th:href="@{/component/pear/css/pear.css}" />
	<link rel="stylesheet" th:href="@{/admin/css/other/login.css}" />
</head>
<!-- 代 码 结 构 -->
<body th:background="@{/admin/images/background2.svg}" style="background-size: cover;">
<form class="layui-form" action="javascript:void(0);">
	<div class="layui-form-item">
		<img class="logo" th:src="@{/admin/images/logo.png}" />
		<div class="title">巍-辉</div>
		<div class="desc">
			为 您 提 供 最 好 的 资 产 服 务
		</div>
	</div>
	<input type="hidden" id="userId" name="userId" th:value="${myUser.userId}">
	<div class="layui-form-item">
		<input id="userName" name="userName" th:value="${myUser.userName}" placeholder="用 户 名 : " type="text" hover class="layui-input" required lay-verify="userName"/>
	</div>
	<div class="layui-form-item">
		<input id="nickName" name="nickName" th:value="${myUser.nickName}" placeholder="昵 称 : " type="text" hover class="layui-input" required lay-verify="nickName"/>
	</div>
	<div class="layui-form-item">
		<input id="phone" name="phone" th:value="${myUser.phone}" placeholder="您 的 电 话 : " type="text" hover class="layui-input" required lay-verify="phone"/>
	</div>
	<div class="layui-form-item">
		<input id="email" name="email" th:value="${myUser.email}" placeholder="您 的 邮 箱 : " type="text" hover class="layui-input" required lay-verify="email"/>
	</div>
	<div class="layui-form-item">
		<input id="password" name="password" th:value="${myUser.password}" placeholder="密 码 : " type="password"  hover class="layui-input" required lay-verify="password"/>
	</div>
	<div class="layui-form-item">
		<input id="passwordVerify" name="passwordVerify" placeholder="确 认 密 码 : " type="password"  hover class="layui-input" required lay-verify="passwordVerify"/>
	</div>
	<div class="layui-form-item">
		<input placeholder="验证码 : " name="captcha" id="captcha" hover class="code layui-input layui-input-inline"  required lay-verify="captcha" />
		<img src="/captcha" class="captchaImage" id="captchaImage" onclick="this.src=this.src+'?'+Math.random()" title="点击刷新"/>
	</div>

	<div class="layui-form-item">
		<button class="layui-btn" lay-submit lay-filter="formRegister">立即提交</button>
	</div>
	<div class="layui-form-item">
		<a href="/main/index">
			返 回 主 页
		</a>
	</div>
</form>
<script th:src="@{/component/layui/layui.js}"></script>
<script>
	layui.use(['form', 'element','jquery'], function() {
		var form = layui.form;
		var element = layui.element;
		var $ = layui.jquery;
		// $("body").on("click",".login",function(obj){
		// 	location.href="/api/admin"
		// })
		form.verify({
			userName: function(value) {
				if (value.length <= 0 ) {
					return '用户名不能为空';
				}
			},
			password: function (value) {
				if (value.length <= 0) {
					return '密码不能为空';
				}
				if(value!=$('#passwordVerify').val()){
					return '两次密码不一致';
				}
			},
			captcha: function (value) {
				if (value.length <= 0) {
					return '验证码不能为空';
				}
				if (value.length !== 4) {
					return '请输入正确格式的验证码';
				}
			},
			//增加的
			nickName: function(value){
				if(value.length < 3){
					return '昵称至少得3个字符啊';
				}
			},
			phone: [/(.+){11,11}$/, '电话号码必须11位'],
			email: [/^[a-z0-9._%-]+@([a-z0-9-]+\.)+[a-z]{2,4}$|^1[3|4|5|7|8]\d{9}$/, '邮箱格式不对']
		})
		form.on('submit(formRegister)', function(data) {

			$.ajax({
				url:'/register/post',
				type:'post',
				dataType:'json',
				contentType:'application/json',
				data:JSON.stringify(data.field),
				success:function(result){
					if (result.success) {
						layer.msg(result.msg,{icon:1,time:1000},function () {
							//这边直接跳到前端首页
							location.href = "/main/index";
						});
					}else {
						layer.msg(result.msg,{icon:2,time:1000},function () {
							$("#captchaImage").attr("src","/captcha" + "?" + Math.random());
						});
						return false;
					}
				}
			})
			return false;
		});
	})
	if(window !=top){
		    top.location.href = location.href;
	}
</script>
</body>
</html>
